home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 3232 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  874 b 

  1. Path: news.acay.com.au!news
  2. From: nsouto@acay.com.au
  3. Newsgroups: comp.lang.c
  4. Subject: Re: quick decision: is n a power of 2?
  5. Date: 27 Jan 1996 03:06:42 GMT
  6. Organization: ACAY Network Computing P/L, Sydney AUSTRALIA.
  7. Message-ID: <4ec4s2$sfs@www.acay.com.au>
  8. References: <Pine.OSF.3.91.960119114608.18779E-100000@io.UWinnipeg.ca>
  9. Reply-To: nsouto@acay.com.au
  10. NNTP-Posting-Host: nsouto.acay.com.au
  11. X-Newsreader: IBM NewsReader/2 v1.2
  12.  
  13. In <Pine.OSF.3.91.960119114608.18779E-100000@io.UWinnipeg.ca>, Bill Simpson <wsimpson@uwinnipeg.ca> writes:
  14. >Is there a fast way to decide whether a number n is a power of 2?
  15. >Bill Simpson
  16.  
  17.  
  18. PMFJI. I may be PITW, but I think the easiest way would be to look at a power of
  19. 2 as a binary number: it's gotta be a 1 followed by zero or more 0's. Ie:
  20.  
  21. 1
  22. 10
  23. 100
  24. 1000
  25. etc.
  26.  
  27. That should be a nice and fast way of looking for a 2*n number? ;-)
  28.  
  29. HTH
  30.  
  31.  
  32.